package com.zbkj.admin.controller.platform;

import com.zbkj.common.model.saleroom.TransferInfo;
import com.zbkj.common.page.CommonPage;
import com.zbkj.common.request.PageParamRequest;
import com.zbkj.common.result.CommonResult;
import com.zbkj.service.service.saleroom.ITransferInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 调货详情Controller
 *
 * @author zkf
 * @date 2025-02-21
 */
@Api("调货详情")
@RestController
@RequestMapping("api/admin/platform/transfer")
public class TransferInfoController {

    @Autowired
    private ITransferInfoService transferInfoService;

    @ApiOperation("查询调货详情列表")
    @PreAuthorize("hasAuthority('stockroom:transfer:list')")
    @GetMapping("/list")
    public CommonResult<CommonPage<TransferInfo>> list(TransferInfo transferInfo, PageParamRequest pageParamRequest) {
        return CommonResult.success(CommonPage.restPage(transferInfoService.selectTransferInfoList(transferInfo, pageParamRequest)));
    }


//    @ApiOperation("导出调货详情列表")
//    @PreAuthorize("hasAuthority('saleroom:saleroom:export')")
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, TransferInfo transferInfo) {
//        List<TransferInfo> list = transferInfoService.selectTransferInfoList(transferInfo);
//        ExcelUtil<TransferInfo> util = new ExcelUtil<TransferInfo>(TransferInfo.class);
//        util.exportExcel(response, list, "调货详情数据");
//    }

    @ApiOperation("获取调货详情详细信息")
    @PreAuthorize("hasAuthority('stockroom:transfer:query')")
    @GetMapping(value = "/{id}")
    public CommonResult<TransferInfo> getInfo(@PathVariable("id") Long id) {
        return CommonResult.success(transferInfoService.selectTransferInfoById(id));
    }


    @ApiOperation("新增调货详情")
    @PreAuthorize("hasAuthority('stockroom:transfer:add')")
    @PostMapping
    public CommonResult<String> add(@RequestBody @Valid TransferInfo transferInfo) {
        if (transferInfoService.insertTransferInfo(transferInfo) >= 1) {
            return CommonResult.success();
        }
        return CommonResult.failed();
    }


    @ApiOperation("修改调货详情")
    @PreAuthorize("hasAuthority('stockroom:transfer:edit')")
    @PutMapping
    public CommonResult<String> edit(@RequestBody TransferInfo transferInfo) {
        if (transferInfoService.updateTransferInfo(transferInfo) >= 1) {
            return CommonResult.success();
        }
        return CommonResult.failed();
    }


    @ApiOperation("删除调货详情")
    @PreAuthorize("hasAuthority('stockroom:transfer:remove')")
    @DeleteMapping("/{ids}")
    public CommonResult<String> remove(@PathVariable Long[] ids) {
        if (transferInfoService.deleteTransferInfoByIds(ids) >= 1) {
            return CommonResult.success();
        }
        return CommonResult.failed();
    }

}